package com.gc.baselib.base;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.gc.baselib.base.event.NavigationEvent;
import com.gc.baselib.base.event.SingleLiveEvent;


/**
 * @author admin
 * @Date 2022/6/10 13:56
 * @package： com.zk.baselib.base
 * @decrpition
 */
public class BaseViewModel extends AndroidViewModel implements IBaseViewModel{
    public CommonEvent commonEvent=new CommonEvent();

    public BaseViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
//        Log.e("aaaaaaaaa",this.getClass().getName()+"   ==== onCleared()");
    }

    @Override
    public void onAny(LifecycleOwner owner, Lifecycle.Event event) {

    }

    @Override
    public void onCreate() {
//        Log.e("aaaaaaaaa",this.getClass().getName()+"   ==== onCreate()");
    }

    @Override
    public void onDestroy() {
//        Log.e("aaaaaaaaa",this.getClass().getName()+"   ==== onDestroy()");
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onStop() {

    }

    @Override
    public void onResume() {
//        Log.e("aaaaaaaaa",this.getClass().getName()+"   ==== onResume()");
    }

    @Override
    public void onPause() {
//        Log.e("aaaaaaaaa",this.getClass().getName()+"   ==== onPause()");
    }

    public void finish()  {
        commonEvent.finishEvent.setValue(null);
    }
    public void back(){
        commonEvent.backEvent.setValue(null);
    }
    public void showSoftKeyBoard(){
        commonEvent.softKeyBoardShowEvent.setValue(true);
    }
    public void hideSoftKeyBoard(){
        commonEvent.softKeyBoardShowEvent.setValue(false);
    }
    public void openPage(NavigationEvent event){
        commonEvent.navEvent.setValue(event);
    }
    public void toast(String content){commonEvent.toastEvent.setValue(content);}
    public final class CommonEvent{
        public SingleLiveEvent<Void> finishEvent=new SingleLiveEvent<>();
        public SingleLiveEvent<Void> backEvent=new SingleLiveEvent<>();
        public SingleLiveEvent<NavigationEvent> navEvent=new SingleLiveEvent<>();
        public SingleLiveEvent<String> toastEvent=new SingleLiveEvent<>();
        public SingleLiveEvent<Boolean> softKeyBoardShowEvent=new SingleLiveEvent<>();

    }

}
